package com.hxkcloud.nurse.dborm;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.table.TableUtils;
import com.hxkcloud.nurse.beans.DoctorGroupBean;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by william_sun on 2016-09-23.
 * Description:
 */
public class DoctorGroupDao {
    private Context context;
    private Dao<DoctorGroupBean, Integer> doctorGroupDao;

    public DoctorGroupDao(Context context) {
        this.context = context;
        try {
            doctorGroupDao = DatabaseHelper.getHelper(context).getDao(DoctorGroupBean.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public List<DoctorGroupBean> getGroup() {
        try {
            return doctorGroupDao.queryForAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void setGroup(List<DoctorGroupBean> groups) {
        try {
            clearGroup();
            for (DoctorGroupBean d : groups) {
                doctorGroupDao.create(d);
            }
        } catch (SQLException e) {
        }
    }

    public void clearGroup() {
        try {
            TableUtils.clearTable(doctorGroupDao.getConnectionSource(), DoctorGroupBean.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
